package net.mattiraty.imagebrowser;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.Menu.Item;

import net.mattiraty.imagebrowser.FilteredFileList;
import net.mattiraty.imagebrowser.R;
import net.mattiraty.imagebrowser.ThumbnailView;

public class Main extends Activity {
	
	public static final int MENUID_THUMBNAILS = Menu.FIRST;	
	
	private String[] mFiles;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        
        String[] imageTypes = {"jpg", "jpeg","gif", "png"};

        FilteredFileList fileList = new FilteredFileList("/data/download/",
        									imageTypes); 
        fileList.load();
        mFiles = fileList.getFiles();
    }
    
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		boolean ret = super.onCreateOptionsMenu(menu);
		
		menu.add(0, MENUID_THUMBNAILS, R.string.menu_thumbnail);
		
		return ret;
	}

	@Override
	public boolean onOptionsItemSelected(Item item) {
		
		switch(item.getId()) {
		case MENUID_THUMBNAILS:
			showThumbnailView();
			break;
		}
		return super.onOptionsItemSelected(item);
	}
	
	/**
	 * Shows thumbnail view
	 */
	private void showThumbnailView() {
		Intent i = new Intent(this, ThumbnailView.class);		
		i.putExtra(ThumbnailView.BUNDLE_EXTRA_FILELIST, mFiles);
		startSubActivity(i, ThumbnailView.ACTIVITY_VIEW);
	}
}